<!DOCTYPE html>
<html>
<head>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
</head>
<body>
    <script>
        if (document.location.hostname == "127.0.0.1") {
            document.location.hostname = "subdomain.example.test";
        } else {
            var t = async_test("Messages' origins are uneffected by 'document.domain'.");

            t.step(function () {
                var i = document.createElement('iframe');
                i.src = 'http://localhost:8000/security/postMessage/resources/post-message-listener.html';
                i.onload = t.step_func(function () {
                    document.domain = 'example.test';

                    i.contentWindow.postMessage('Message from parent', '*');
                });
                document.body.appendChild(i);
            });

            window.addEventListener('message', t.step_func(function (e) {
              assert_equals(e.data, 'Received message: data="Message from parent" origin="http://subdomain.example.test:8000"');
              t.done(); 
            }));
        }
    </script>
</body>
</html>
